vm/op.go
func (o *op) UnmarshalBinary(data []byte) error {
	buf := bytes.NewReader(data)

	var t int64
	if err := binary.Read(buf, binary.LittleEndian, &t); err != nil {
		return errors.Wrap(err, "optype check failed during UnmarshalBinary")
	}

	o.OpType = OpType(t)
	o.OpHandler = optypeToHandler(o.OpType)

	var hasArg int8
	if err := binary.Read(buf, binary.LittleEndian, &hasArg); err != nil {
		return errors.Wrap(err, "hasArg check failed during UnmarshalBinary")
	}

	if hasArg == 1 {
		var tArg int64
		if err := binary.Read(buf, binary.LittleEndian, &tArg); err != nil {
			return errors.Wrap(err, "failed to read argument from buffer during UnmarshalBinary")
		}

		switch tArg {
		case 2:
			var i int64
			if err := binary.Read(buf, binary.LittleEndian, &i); err != nil {
				return errors.Wrap(err, "failed to read integer argument during UnmarshalBinary")
			}
			o.uArg = i
		case 5:
			var l int64
			if err := binary.Read(buf, binary.LittleEndian, &l); err != nil {
				return errors.Wrap(err, "failed to read length argument during UnmarshalBinary")
			}

			b := make([]byte, l)
			for i := int64(0); i < l; i++ {
				if err := binary.Read(buf, binary.LittleEndian, &b[i]); err != nil {
					return errors.Wrap(err, "failed to read bytes from buffer during UnmarshalBinary")
				}
			}
			o.uArg = b
		default:
			panic(fmt.Sprintf("Unknown tArg: %d", tArg))
		}
	}

	var hasComment int8
	if err := binary.Read(buf, binary.LittleEndian, &hasComment); err != nil {
		return errors.Wrap(err, "hasComment check failed during UnmarshalBinary")
	}

	if hasComment == 1 {
		if err := binary.Read(buf, binary.LittleEndian, &o.comment); err != nil {
			return errors.Wrap(err, "failed to read comment bytes during UnmarshalBinary")
		}
	}

	return nil
}
func (o *op) UnmarshalBinary(data []byte) error {
	buf := bytes.NewReader(data)

	var t int64
	if err := binary.Read(buf, binary.LittleEndian, &t); err != nil {
		return errors.Wrap(err, "optype check failed during UnmarshalBinary")
	}

	o.OpType = OpType(t)
	o.OpHandler = optypeToHandler(o.OpType)

	var hasArg int8
	if err := binary.Read(buf, binary.LittleEndian, &hasArg); err != nil {
		return errors.Wrap(err, "hasArg check failed during UnmarshalBinary")
	}

	if hasArg == 1 {
		var tArg int64
		if err := binary.Read(buf, binary.LittleEndian, &tArg); err != nil {
			return errors.Wrap(err, "failed to read argument from buffer during UnmarshalBinary")
		}

		switch tArg {
		case 2:
			var i int64
			if err := binary.Read(buf, binary.LittleEndian, &i); err != nil {
				return errors.Wrap(err, "failed to read integer argument during UnmarshalBinary")
			}
			o.uArg = i
		case 5:
			var l int64
			if err := binary.Read(buf, binary.LittleEndian, &l); err != nil {
				return errors.Wrap(err, "failed to read length argument during UnmarshalBinary")
			}

			b := make([]byte, l)
			for i := int64(0); i < l; i++ {
				if err := binary.Read(buf, binary.LittleEndian, &b[i]); err != nil {
					return errors.Wrap(err, "failed to read bytes from buffer during UnmarshalBinary")
				}
			}
			o.uArg = b
		default:
			panic(fmt.Sprintf("Unknown tArg: %d", tArg))
		}
	}

	var hasComment int8
	if err := binary.Read(buf, binary.LittleEndian, &hasComment); err != nil {
		return errors.Wrap(err, "hasComment check failed during UnmarshalBinary")
	}

	if hasComment == 1 {
		if err := binary.Read(buf, binary.LittleEndian, &o.comment); err != nil {
			return errors.Wrap(err, "failed to read comment bytes during UnmarshalBinary")
		}
	}

	return nil
}
// UnmarshalBinary is used to deserialize an Op from binary form.