Remove RawEnvelope, RawPacket, and RawData from DecodedPacket struct

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Daniel Pupius
2025-04-21 10:30:15 -07:00
parent 52ed85ed23
commit 9b73057103
3 changed files with 6 additions and 57 deletions
+2 -8
View File
@@ -149,14 +149,8 @@ func TestDecodeMessageWithMapPayload(t *testing.T) {
t.Errorf("Expected PortNum to be MAP_REPORT_APP, got %s", decodedPacket.PortNum)
}
// Check that all key fields were populated
if decodedPacket.RawEnvelope == nil {
t.Error("Expected RawEnvelope to be populated")
}
if decodedPacket.RawPacket == nil {
t.Error("Expected RawPacket to be populated")
}
// These fields are no longer used
// Only verify that key metadata was correctly extracted
// Verify that key metadata was correctly extracted
if decodedPacket.From == 0 {
+3 -11
View File
@@ -40,11 +40,6 @@ type DecodedPacket struct {
Source uint32
WantResponse bool
// Raw message objects (for advanced use)
RawEnvelope *pb.ServiceEnvelope
RawPacket *pb.MeshPacket
RawData *pb.Data
// Error tracking
DecodeError error
}
@@ -135,8 +130,7 @@ func DecodeMessage(payload []byte, topicInfo *TopicInfo) *DecodedPacket {
return decoded
}
// Store raw envelope
decoded.RawEnvelope = envelope
// Extract envelope fields without storing raw envelope
// Extract envelope fields
decoded.ChannelID = envelope.GetChannelId()
@@ -149,8 +143,7 @@ func DecodeMessage(payload []byte, topicInfo *TopicInfo) *DecodedPacket {
return decoded
}
// Store raw packet
decoded.RawPacket = packet
// Extract mesh packet fields without storing raw packet
// Extract mesh packet fields
decoded.ID = packet.GetId()
@@ -180,8 +173,7 @@ func DecodeMessage(payload []byte, topicInfo *TopicInfo) *DecodedPacket {
// decodeDataPayload extracts information from a Data message
func decodeDataPayload(decoded *DecodedPacket, data *pb.Data) {
// Store raw data
decoded.RawData = data
// Extract data fields without storing raw data
// Extract data fields
decoded.PortNum = data.GetPortnum()
+1 -38
View File
@@ -745,44 +745,7 @@ func FormatDecodedPacket(packet *DecodedPacket) string {
builder.WriteString(fmt.Sprintf("Error decoding packet: %v\n", packet.DecodeError))
// Show raw data in different formats for debugging
if packet.RawData != nil && packet.RawData.GetPayload() != nil {
rawData := packet.RawData.GetPayload()
builder.WriteString(fmt.Sprintf("Raw data (%d bytes):\n", len(rawData)))
builder.WriteString(fmt.Sprintf(" Hex: %x\n", rawData))
// Show binary representation
builder.WriteString(" Binary: ")
for i, b := range rawData {
if i > 0 && i%8 == 0 {
builder.WriteString(" ")
}
if i > 0 && i%32 == 0 {
builder.WriteString("\n ")
}
builder.WriteString(fmt.Sprintf("%08b ", b))
// Limit to first 32 bytes for binary representation
if i >= 31 {
builder.WriteString("...\n")
break
}
}
// Show as text if it might be displayable
if IsASCII(rawData) {
builder.WriteString(fmt.Sprintf(" Text: %s\n", string(rawData)))
}
} else if packet.RawPacket != nil && packet.RawPacket.GetEncrypted() != nil {
// Show raw encrypted data if available
encData := packet.RawPacket.GetEncrypted()
builder.WriteString(fmt.Sprintf("Raw encrypted data (%d bytes):\n", len(encData)))
builder.WriteString(fmt.Sprintf(" Hex: %x\n", encData))
// Show as text only if it looks like ASCII (rare for encrypted data)
if IsASCII(encData) {
builder.WriteString(fmt.Sprintf(" Text: %s\n", string(encData)))
}
} else if packet.Payload != nil {
if packet.Payload != nil {
// If we have a payload but an error occurred during decoding
if data, ok := packet.Payload.([]byte); ok {
builder.WriteString(fmt.Sprintf("Raw payload (%d bytes):\n", len(data)))