' Collection of code snippets by Arne Vajhøj 
' (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
﻿Imports System
Imports System.IO

Imports Vajhoej.Record

Namespace May1
    '     * 0-3 = Pakkenummer
    '     * 4-10 = unixtime dato
    '     * 11-32 = null
    '     * 33-slut = text
    <Struct(Endianess := Endian.BIG)> _
    Public Class Package
        <StructField(N := 0, Type := FieldType.INT4)> _
        Private packno As Integer
        <StructField(N := 1, Type := FieldType.INTX, Length := 7)> _
        Private unixtim As ULong
        <ArrayField(Elements := 22)> _
        <StructField(N := 2, Type := FieldType.UINT1)> _
        Private filler As Byte() = New Byte(21) {}
        <StructField(N := 3, Type := FieldType.REMSTR, Encoding := "ISO-8859-1")> _
        Private txt As [String]
        Public ReadOnly Property PackageNumber() As Integer
            Get
                Return packno
            End Get
        End Property
        Public ReadOnly Property UnixTimestamp() As ULong
            Get
                Return unixtim
            End Get
        End Property
        Public ReadOnly Property Text() As [String]
            Get
                Return txt
            End Get
        End Property
    End Class
    Public Class Program
        Public Shared Sub Main(args As String())
            Dim b As Byte() = { 0, 0, 0, 1, _
                                1, 2, 3, 4, 5, 6, 7, _
                                0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,  0, 0, 0, 0, 0, 0, 0, 0, 0, _
                                65, 66, 67 }
            Dim sr As New StructReader(b)
            Dim o As Package = sr.Read(Of Package)(GetType(Package))
            Console.WriteLine(o.PackageNumber & " " & o.UnixTimestamp.ToString("X") & " " & o.Text)
        End Sub
    End Class
End Namespace
